package la.bbs558.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import la.bbs558.context.PointContext;
import la.bbs558.dao.UserPointsLogDao;
import la.bbs558.entity.UserPointsLog;
import la.bbs558.entity.enums.PointsOptType;
import la.bbs558.handler.PointsHandler;
import la.bbs558.service.UserPointsLogService;
import la.bbs558.util.ApplicationUtils;
import org.springframework.stereotype.Service;

/**
 * 用户表角色(UserPointsLog)表服务实现类
 *
 * @author weihanmin
 * @since 2023-12-15 13:12:38
 */
@Service("userPointsLogService")
public class UserPointsLogServiceImpl extends ServiceImpl<UserPointsLogDao, UserPointsLog> implements UserPointsLogService {


    @Override
    public void getPoints(PointContext context) {
        if(context.getUserId() == null){
            context.setUserId(StpUtil.getLoginIdAsLong());
        }
        PointsOptType pointsOptType = context.getOptType();
        PointsHandler getPointsActionHandler = ApplicationUtils.getBean(pointsOptType.getHandlerClass());
        getPointsActionHandler.action(context);
    }
}

